package com.goodving.guli.bt;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.XMBLEManager;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.utility.gulihardware.Constant;

/**
 * Created by john on 2015/11/28.
 */
public class SystemBindReceiver extends BroadcastReceiver {
    private static final String TAG;

    static {
        TAG = SystemBindReceiver.class.getSimpleName();
    }

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action != null) {
            GuliLog.tracePrintInfo(TAG, "action:" + action);
            BluetoothDevice bluetoothDevice;
            if (action.equals(Constant.aW)) {
                bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
                if (bluetoothDevice != null) {
                    GuliLog.tracePrintInfo(TAG, "bind device:" + bluetoothDevice.getAddress());
                }
            } else if (action.equals(Constant.aX)) {
                bluetoothDevice = (BluetoothDevice) intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
                if (bluetoothDevice != null) {
                    GuliLog.tracePrintInfo(TAG, "unbind device:" + bluetoothDevice.getAddress());
                }
            } else if (action.equals("android.intent.action.BOOT_COMPLETED")) {
                XMBLEManager.startBleServiceForDevice(context.getApplicationContext(), Keeper.readBraceletBtInfo().f19636b, Utils.m8093p());
            } else if (action.equals("android.intent.action.USER_PRESENT")) {
                XMBLEManager.startBleServiceForDevice(context.getApplicationContext(), Keeper.readBraceletBtInfo().f19636b, Utils.m8093p());
            }
        }
    }
}
